<?php

namespace Admin\Controller;


// +----------------------------------------------------------------------
// | 文件 DeviceController.class.php
// +----------------------------------------------------------------------
// | 说明 设备推荐的配置管理
// +----------------------------------------------------------------------
// | 
// +----------------------------------------------------------------------
// | Author: 谢赤心 Legend. <xcx_legender@qq.com>
// +----------------------------------------------------------------------

use Api\Event\Cache\DeviceRemEvent;
use Api\Event\DeviceEvent;

class DeviceController extends AdminController 
{
	// 首页
	public function index()
	{
		$this->display();
	}

	// 导入配置
	public function import()
	{
		extract(I(''));
		if (empty($type)){
			$this->error('请选择类型');
		}

		if (IS_POST)
		{
			if (empty($content)){
				$this->error('请填写完整导入的数据!');
			}
			$lists = explode("\r\n", $content);
			DeviceRemEvent::set($type, $lists);
			$this->success('操作成功');
		}else{
			$lists = DeviceRemEvent::get($type);
			$config = DeviceRemEvent::get_score($type);
			$this->assign('lists', $lists);
			$this->assign('config', $config);
			$this->display();
		}

	}

	public function set_score()
	{
		extract(I(''));
		if (empty($type)){
			$this->error('请选择类型');
		}
		if (empty($config)){
			$this->error('请填写配置信息!');
		}

		$res = DeviceRemEvent::set_score($type, $config);
		if (!$res){
			$this->error('配置格式错误');
		}
		else{
			$this->success('配置成功');
		}
	}

	public function test()
	{
		extract(I(''));
		if (empty($type)){
			$this->error('请选择类型');
		}
		if (empty($key)){
			$this->error('请填写型号!');
		}

		$value = DeviceEvent::calculateType($type, $key);
		$this->error("SCORE: ". $value);
	}


}